/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.uniminuto.arqSw.videoMinuto.servlets;


import co.uniminuto.edu.videominuto.entities.TipoCalificacion;
import co.uniminuto.edu.videominuto.entities.TipoPersona;
import co.uniminuto.edu.videominuto.sessionBeans.CategoriaFacade;
import co.uniminuto.edu.videominuto.sessionBeans.CategoriaFacadeLocal;
import co.uniminuto.edu.videominuto.sessionBeans.ClasificacionFacade;
import co.uniminuto.edu.videominuto.sessionBeans.ClasificacionFacadeLocal;
import co.uniminuto.edu.videominuto.sessionBeans.FormatoFacade;
import co.uniminuto.edu.videominuto.sessionBeans.FormatoFacadeLocal;
import co.uniminuto.edu.videominuto.sessionBeans.IdiomaFacade;
import co.uniminuto.edu.videominuto.sessionBeans.IdiomaFacadeLocal;
import co.uniminuto.edu.videominuto.sessionBeans.TipoCalificacionFacade;
import co.uniminuto.edu.videominuto.sessionBeans.TipoCalificacionFacadeLocal;
import co.uniminuto.edu.videominuto.sessionBeans.TipoPersonaFacade;
import co.uniminuto.edu.videominuto.sessionBeans.TipoPersonaFacadeLocal;
import co.uniminuto.edu.videominuto.sessionBeans.VideoFacade;
import co.uniminuto.edu.videominuto.sessionBeans.VideoFacadeLocal;
import java.io.IOException;
import java.io.Serializable;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.EJBs;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
        

/**
 *
 * @author Juan
 */
public class VideoServlet extends HttpServlet implements Serializable{
    
    @EJB
    VideoFacadeLocal vf;
    @EJB
    CategoriaFacadeLocal cf;
    @EJB
    FormatoFacadeLocal ff;
    @EJB
    TipoPersonaFacadeLocal tpf;
    @EJB
    ClasificacionFacadeLocal clf;
    @EJB
    IdiomaFacadeLocal idf;
    @EJB
    TipoCalificacionFacadeLocal tcf;
    
    
    public static final Logger logger =Logger.getLogger(VideoServlet.class.getName());
    
    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        
        Hashtable<String, String> hashParametros = new Hashtable<String, String>();
        Enumeration en = request.getParameterNames();
        
        while (en.hasMoreElements()) {
            String paramName = (String) en.nextElement();
            hashParametros.put(paramName,  request.getParameter(paramName));
        }
        
        
        
      //  VideoDAO vd=new VideoDAO();
        
        request.setAttribute("categorias", cf.findAll());
        request.setAttribute("formatos", ff.findAll());
        request.setAttribute("roles", tpf.findAll());
        request.setAttribute("idiomas", idf.findAll());
        request.setAttribute("clasificaciones", clf.findAll());
        request.setAttribute("tipo_calificaciones", tcf.findAll());
       
        //System.out.print(vd.busqueda(hashParametros));
        
        //Asigancion de la variables videos
        request.setAttribute("videos", vf.getVideos(hashParametros));
        
        request.getRequestDispatcher("/paginas/video/busquedaVideos.jsp").forward(request, response);
        
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
